package com.wu.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.wu.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @ClassName NewsController
 * @Author wuxuan
 * @Date 2019/2/20 21:28
 * @Version 1.0
 * @Description
 **/
@RestController
@Scope("prototype")
public class NewsController {

    @Autowired
    @Qualifier(value = "articleService")
    ArticleService service;

    ObjectMapper mapper=new ObjectMapper();

    @GetMapping("/news/{newsType}")
    public String getNews(@PathVariable String newsType) throws JsonProcessingException {
        List<Map> news = service.getNews(newsType);
        return mapper.writeValueAsString(news);
    }

}
